package com.mini.framework.communicate.mina.protocol;

import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;

import com.mini.framework.communicate.mina.adapter.MsgDecoderAdapter;
import com.mini.framework.communicate.mina.adapter.MsgEncoderAdapter;

public class ProtocolCodeFactory extends DemuxingProtocolCodecFactory {
	
	private CodeFactory factory;
	
	public ProtocolCodeFactory(CodeFactory factory){
		this.factory = factory;
		registCodeFactory();
	}
	
	public void registCodeFactory(){
		Encoder[] encoders = factory.getEncoder();
		
		if(encoders != null){
			for(int i = 0;i<encoders.length;i++){
				//this.register(new MsgEncoderAdapter(encoders[i]));
				addMessageEncoder(encoders[i].getMsgType(), new MsgEncoderAdapter(encoders[i]));
			}
		}
		
		Decoder[] decoders = factory.getDecoder();
		if(decoders != null){
			for(int j = 0;j<decoders.length;j++){
				//this.register(new MsgDecoderAdapter(decoders[j]));
				addMessageDecoder(new MsgDecoderAdapter(decoders[j]));
				
			}
		}
		
	}
	

}
